let str = "abbaca"

// 输入："abbaca"
// 输出："ca"

var removeDuplicates = function (s) {
  let stack = []
  for (let i = 0; i < s.length; i++) {
    if (stack.length === 0 || s[i] !== stack[stack.length - 1]) {
      stack.push(s[i])
    } else {
      stack.pop()
    }
  }
  return stack.join('')
};

console.log(removeDuplicates(str));
